package cn.lls.base.util;


import java.util.Random;

/**
 * 邮件工具类
 *
 * @ClassName EmailUtil
 * @Author 划水艺术家
 * @Date 2022/11/20 16:39
 * @Version 1.0
 **/
public class EmailUtil {

    private static final char[] ch = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
            'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
            'j', 'k','l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

    private static final Random random;

    private static final int len;

    static {
        random = new Random();
        len = ch.length;
    }

    /*
        随机生成验证码
     */
    public static String creatCode(int n){
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; ++i)
            sb.append(ch[random.nextInt(len)]);
        return sb.toString();
    }

    public static String creatCode(){
        // 默认 6 位验证码
        return creatCode(6);
    }

    public static void main(String[] args) {
        String s = EmailUtil.creatCode();
        System.out.println(s);
    }

}
